﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ProgNetComponents.Validation.Rules
{
    /// <summary>
    /// Rule for checking column decimal value range
    /// </summary>
    public class ColumnDecimalRangeValidationRule : ColumnInRangeRule<decimal>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnDecimalRangeValidationRule"/> class.
        /// </summary>
        public ColumnDecimalRangeValidationRule()
        {
            MinValue = 0;
            MaxValue = 100;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnDecimalRangeValidationRule"/> class.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="min">The minimum.</param>
        /// <param name="max">The maximum.</param>
        /// <param name="error">The error.</param>
        public ColumnDecimalRangeValidationRule(string column, decimal min, decimal max, string error = null)
            : base(column, min, max, error)
        {
            this.MinValue = min;
            this.MaxValue = max;
        }

        /// <summary>
        /// Does the validate.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        protected override bool DoValidate(DataRow row)
        {
            decimal val = row[Column].AsDecimal();
            return val >= MinValue && val <= MaxValue;
        }
    }

}